﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Data;
using Newtonsoft.Json;
using DAL;
using System.Web.SessionState;
using System.Collections;
using OpenFlashChart;

namespace AjaxLibrary
{
    class BusinessNaturePrice
    {
        public int ProductId { get; set; }
        public decimal Price { get; set; }
        public string BusinessNature { get; set; }
        public string Unit { get; set; }
    }
    class product : IHttpHandler, IRequiresSessionState
    {
        bool IHttpHandler.IsReusable
        {
            get { return true; }
        }

        void IHttpHandler.ProcessRequest(HttpContext context)
        {
            string param = context.Request.QueryString["Param"];

            switch (param.ToLower())
            {
                case "getproductno":
                    int categoryId = Convert.ToInt32(context.Request.QueryString["category"]);
                    context.Response.Output.Write(logic.product.getAutoProductNo(categoryId));
                    break;
                case "listsubcateogry":
                    listSubCateogry(context.Request, context.Response);
                    break;
                case "listproduct":
                    listProduct(context.Request, context.Response);
                    break;
                case "listproductlist":
                    listProductList(context.Request, context.Response);
                    break;
                case "getproductprice":
                    getProductPrice(context.Request, context.Response);
                    break;
                case "getproductpricebyrecepe":
                    getProductPriceByRecepe(context.Request, context.Response);
                    break;
                case "getdetail":
                    getProductDetail(context.Request, context.Response);
                    break;
                case "getfavouriteproducts":
                    //getFavouriteProducts(context.Request, context.Response);
                    getFavouriteProducts_New(context.Request, context.Response);
                    break;
                case "gt":
                    getProductGPMByProductId(context.Request, context.Response);
                    break;
                case "getsupplycancelproductlist":
                    getSupplyCancelProductList(context.Request, context.Response);
                    break;
                case "sellercancelsupply":
                    sellerCancelSupply(context.Request, context.Response);
                    break;
                case "sellersubmitprice":
                    sellerSubmitPrice(context.Request, context.Response);
                    break;
                case "getspecialsproduct":
                    getProductPriceSpecials(context.Request, context.Response);
                    break;
                case "setfavourite":
                    setFavourite(context.Request, context.Response);
                    break;
                case "getproductfixedprice":
                    getProductFixedPrice(context.Request, context.Response);
                    break;
                case "getbyproductno":
                    getByProductNo(context.Request, context.Response);
                    break;
                default:
                    context.Response.Output.Write("Unknow request URL---");
                    break;
            }
        }

        private void setFavourite(HttpRequest request, HttpResponse response)
        {
            int srId = 0;
            int.TryParse(request.QueryString["srId"], out srId);

            if (srId != 0)
            {
                logic.sellerRange.setFavourite(srId);
                response.Output.Write("1");
            }
            else
            {
                response.Output.Write("0");
            }
        }

        /// <summary>
        /// code:1表示超过报价时间;2表示发生错误，无法提交；3表示提交报价成功.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        private void sellerSubmitPrice(HttpRequest request, HttpResponse response)
        {
            string REQUEST_ERROR = "{\"code\":\"2\"}";
            string OUT_OF_LIMITED_TIME = "{\"code\":\"1\"}";
            string CURRENT_IS_NOTSUPPLY = "{\"code\":\"4\"}";

            if (!string.IsNullOrEmpty(request.QueryString["w"])) // f表示前台供应商提交；a表示后台操作人员提交;
            {
                if (!string.IsNullOrEmpty(request.QueryString["tArray"]))
                {
                    try
                    {
                        int companyId = 0;
                        if (request.QueryString["w"] == "a")
                        {
                            int.TryParse(request.QueryString["companyId"], out companyId);
                        }
                        else if (request.QueryString["w"] == "f")
                        {
                            companyId = logic.customer.companyId;
                        }
                        int productId = 0;

                        List<BusinessNaturePrice> businessNaturePriceList = JsonConvert.DeserializeObject<List<BusinessNaturePrice>>(request.QueryString["tArray"]);

                        if (businessNaturePriceList.Count > 0)
                        {
                            #region 报价时间判断

                            if (request.QueryString["w"] == "f" && logic.customer.userId != 0)
                            {
                                DateTime updatePriceDt = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + logic.webset.list().UpdatePriceDt);
                                if (DateTime.Now >= updatePriceDt)
                                {
                                    response.Output.Write(OUT_OF_LIMITED_TIME);
                                    return;
                                }
                            }
                            #endregion

                            #region 提交报价操作
                            foreach (BusinessNaturePrice item in businessNaturePriceList)
                            {
                                bool isSupply = logic.sellerRange.IsSupply(companyId, item.ProductId, item.BusinessNature);
                                if (!isSupply)
                                {
                                    PriceSellerEntity ps = new PriceSellerEntity();
                                    ps.ProductId = item.ProductId;
                                    productId = item.ProductId;
                                    ps.SellerPrice = item.Price;
                                    ps.Unit = item.Unit;
                                    if (request.QueryString["w"] == "f") //前台供应商报价
                                    {
                                        ps.SellerId = companyId;
                                        ps.CustomerId = logic.customer.userId;
                                        ps.Source = "1";
                                        ps.AdminId = 0;
                                        ps.ContactMan = "";
                                        ps.Reason = "";
                                    }
                                    else if (request.QueryString["w"] == "a") // 后台操作人员报价
                                    {
                                        ps.SellerId = companyId;
                                        ps.CustomerId = 0;
                                        ps.Source = "2";
                                        ps.AdminId = logic.sysAdmin.AdminID;
                                        ps.ContactMan = request.QueryString["contactMan"];
                                        ps.Reason = request.QueryString["reason"];
                                    }
                                    ps.BusinessNature = item.BusinessNature;
                                    logic.priceSeller.updatePriceV2(ps);
                                }
                                else
                                {
                                    response.Output.Write(CURRENT_IS_NOTSUPPLY);
                                    return;
                                }
                            }

                            #endregion

                            #region 更新价格数据
                            DataTable dt = logic.price.listWithBusinessNatures(productId, companyId);
                            using (JsonTextWriter jsonWriter = new JsonTextWriter(response.Output))
                            {
                                jsonWriter.WriteStartObject();
                                jsonWriter.WritePropertyName("code");
                                jsonWriter.WriteValue("3");
                                jsonWriter.WritePropertyName("productId");
                                jsonWriter.WriteValue(productId);
                                jsonWriter.WritePropertyName("priceArray");

                                jsonWriter.WriteStartArray();
                                foreach (DataRow row in dt.Rows)
                                {
                                    jsonWriter.WriteStartObject();

                                    jsonWriter.WritePropertyName("businessNatureName");
                                    jsonWriter.WriteValue(row["businessNatureName"]);
                                    jsonWriter.WritePropertyName("sellerPrice");
                                    jsonWriter.WriteValue(string.Format("{0:F2}", row["sellerPrice"]));
                                    jsonWriter.WritePropertyName("businessNature");
                                    jsonWriter.WriteValue(row["businessNature"]);
                                    jsonWriter.WritePropertyName("unit");
                                    jsonWriter.WriteValue(row["unit"]);

                                    jsonWriter.WriteEndObject();
                                }
                                jsonWriter.WriteEndArray();

                                jsonWriter.WriteEndObject();
                            }
                            #endregion
                        }
                        else
                        {
                            response.Output.Write(REQUEST_ERROR);
                        }
                    }
                    catch
                    {
                        response.Output.Write(REQUEST_ERROR);
                    }
                }
                else
                {
                    response.Output.Write(REQUEST_ERROR);
                }
            }
            else
            {
                response.Output.Write(REQUEST_ERROR);
            }
        }

        private void sellerCancelSupply(HttpRequest request, HttpResponse response)
        {
            try
            {
                int srId = 0;
                int.TryParse(request.QueryString["srId"], out srId);
                int cancelSuplly = -1;
                int.TryParse(request.QueryString["supllyStatus"], out cancelSuplly);

                SellerRangeEntity sr = new SellerRangeEntity();
                sr.SrId = srId;
                sr.IsCancel = (cancelSuplly == 1);
                int adminId = 0;

                if (!string.IsNullOrEmpty(request.QueryString["w"]))
                {
                    if (request.QueryString["w"] == "a")
                    {
                        adminId = logic.sysAdmin.AdminID;
                    }
                    else if (request.QueryString["w"] == "f")
                    {
                        adminId = logic.customer.userId;
                    }
                }

                sr.AdminId = adminId;
                logic.sellerRange.updateCancel(sr);

                SellerRangeEntity curSellerRange = logic.sellerRange.getById(srId);

                DataTable dt = logic.price.listWithBusinessNatures(curSellerRange.ProductId, curSellerRange.CompanyId);
                using (JsonTextWriter jsonWriter = new JsonTextWriter(response.Output))
                {
                    jsonWriter.WriteStartObject();
                    jsonWriter.WritePropertyName("code");
                    jsonWriter.WriteValue("1");
                    jsonWriter.WritePropertyName("productId");
                    jsonWriter.WriteValue(curSellerRange.ProductId);
                    jsonWriter.WritePropertyName("priceArray");

                    jsonWriter.WriteStartArray();
                    foreach (DataRow row in dt.Rows)
                    {
                        jsonWriter.WriteStartObject();

                        jsonWriter.WritePropertyName("businessNatureName");
                        jsonWriter.WriteValue(row["businessNatureName"]);
                        jsonWriter.WritePropertyName("sellerPrice");
                        jsonWriter.WriteValue(string.Format("{0:F2}", row["sellerPrice"]));
                        jsonWriter.WritePropertyName("businessNature");
                        jsonWriter.WriteValue(row["businessNature"]);
                        jsonWriter.WritePropertyName("unit");
                        jsonWriter.WriteValue(row["unit"]);

                        jsonWriter.WriteEndObject();
                    }
                    jsonWriter.WriteEndArray();

                    jsonWriter.WriteEndObject();
                }
            }
            catch (Exception ex)
            {
                logic.sysLog.insertFacade(ex.Message);
                using (JsonTextWriter jsonWriter = new JsonTextWriter(response.Output))
                {
                    jsonWriter.WriteStartObject();
                    jsonWriter.WritePropertyName("code");
                    jsonWriter.WriteValue("1");
                    jsonWriter.WriteEndObject();
                }
            }
        }

        private void getSupplyCancelProductList(HttpRequest request, HttpResponse response)
        {
            string productIds = request.QueryString["productIds"];
            DataTable dt = logic.product.getSupplyCancelProductList(productIds);

            if (dt.Rows.Count > 0)
            {
                using (JsonWriter writer = new JsonTextWriter(response.Output))
                {
                    writer.WriteStartArray();
                    foreach (DataRow row in dt.Rows)
                    {
                        writer.WriteStartObject();
                        writer.WritePropertyName("productName");
                        writer.WriteValue(row["name"]);
                        writer.WriteEndObject();
                    }
                    writer.WriteEndArray();
                }
            }
            else
            {
                response.Output.Write("[]");
            }
        }

        private void getProductGPMByProductId(HttpRequest request, HttpResponse response)
        {
            int productId = 0;
            int.TryParse(request.QueryString["productId"], out productId);

            if (productId != 0)
            {
                int year = DateTime.Now.Year;
                int.TryParse(request.QueryString["year"], out year);

                DataSet ds = logic.product.productMonthGPMlistByProductAndYear(productId, year);
                string productName = ds.Tables[0].Rows[0]["name"].ToString();
                DataTable dt = ds.Tables[1];

                OpenFlashChart.OpenFlashChart chart = new OpenFlashChart.OpenFlashChart();

                ArrayList data1 = new ArrayList();
                IList<string> weekLabels = new List<string>();

                foreach (DataRow row in dt.Rows)
                {
                    data1.Add(new LineDotValue(Convert.ToDouble(row["gpm"]), string.Format("{0}月平均毛利{1}", row["month"], row["gpm"]), "#fe0"));
                    weekLabels.Add(row["month"].ToString());
                }

                OpenFlashChart.LineHollow line1 = new LineHollow();
                line1.Values = data1;
                line1.HaloSize = 0;
                line1.Width = 2;
                line1.DotSize = 5;
                line1.Text = "商品月平均毛利";

                line1.Tooltip = "提示：#val#";

                chart.X_Axis.Labels.SetLabels(weekLabels);

                chart.AddElement(line1);

                chart.Title = new Title(string.Format("{0}{1}年月平均毛利", productName, year));
                chart.Y_Axis.SetRange(0, 1000, 100);
                chart.Tooltip = new ToolTip("全局提示：#val#");
                chart.Tooltip.Shadow = true;
                chart.Tooltip.Colour = "#e43456";
                chart.Tooltip.MouseStyle = ToolTipStyle.CLOSEST;

                response.Clear();
                response.CacheControl = "no-cache";
                response.Write(chart.ToPrettyString());
                response.End();
            }
        }

        // 偏好设置订单
        private void getFavouriteProducts(HttpRequest httpRequest, HttpResponse httpResponse)
        {
            int week = 0;
            int.TryParse(httpRequest.QueryString["week"], out week);

            DataTable dt = logic.companyWeek.getProductsWithPriceByWeek(week, logic.customer.getCompanyId());

            if (dt.Rows.Count > 0)
            {
                using (JsonTextWriter writer = new JsonTextWriter(httpResponse.Output))
                {
                    writer.WriteStartArray();
                    foreach (DataRow row in dt.Rows)
                    {
                        writer.WriteStartObject();
                        writer.WritePropertyName("productId");
                        writer.WriteValue(row["productId"]);
                        writer.WritePropertyName("productName");
                        writer.WriteValue(row["name"]);
                        writer.WritePropertyName("unit");
                        writer.WriteValue(row["unit"]);
                        writer.WritePropertyName("newPrice");
                        writer.WriteValue(string.Format("{0:F2}", row["newPrice"]));
                        writer.WritePropertyName("isCurrentCost");
                        writer.WriteValue(Convert.ToInt32(row["isCurrentCost"]));
                        writer.WritePropertyName("remarks");
                        if (row["remarks"] != DBNull.Value)
                            writer.WriteValue(row["remarks"]);
                        else
                            writer.WriteValue("");
                        writer.WriteEndObject();
                    }
                    writer.WriteEndArray();
                }
            }
            else
            {
                httpResponse.Output.Write("[]");
            }
        }

        // 偏好设置订单
        private void getFavouriteProducts_New(HttpRequest httpRequest, HttpResponse httpResponse)
        {
            int week = 0;
            int.TryParse(httpRequest.QueryString["week"], out week);

            DataTable dt = logic.companyWeek.getProductsWithPriceByWeek(week, logic.customer.getCompanyId());

            if (dt.Rows.Count > 0)
            {
                using (JsonTextWriter writer = new JsonTextWriter(httpResponse.Output))
                {
                    writer.WriteStartArray();
                    foreach (DataRow row in dt.Rows)
                    {
                        writer.WriteStartObject();
                        writer.WritePropertyName("productId");
                        writer.WriteValue(row["productId"]);

                        writer.WritePropertyName("name");
                        writer.WriteValue(row["name"]);

                        writer.WritePropertyName("unit");
                        writer.WriteValue(row["unit"]);

                        writer.WritePropertyName("newprice");
                        writer.WriteValue(string.Format("{0:F2}", row["newPrice"]));

                        writer.WritePropertyName("isCurrentPrice");
                        writer.WriteValue(Convert.ToInt32(row["isCurrentCost"]));

                        writer.WritePropertyName("systemName");
                        writer.WriteValue(row["systemName"]);

                        writer.WritePropertyName("remarks");
                        if (row["remarks"] != DBNull.Value)
                            writer.WriteValue(row["remarks"]);
                        else
                            writer.WriteValue("");

                        writer.WritePropertyName("sellerId");
                        writer.WriteValue(row["sellerId"]);

                        writer.WritePropertyName("sellerPrice");
                        writer.WriteValue(row["sellerPrice"]);

                        writer.WritePropertyName("bookamount");
                        writer.WriteValue(row["bookamount"]);

                        writer.WritePropertyName("businessNature");
                        writer.WriteValue(row["businessNature"]);

                        writer.WriteEndObject();
                    }
                    writer.WriteEndArray();
                }
            }
            else
            {
                httpResponse.Output.Write("[]");
            }
        }

        private void getProductDetail(HttpRequest httpRequest, HttpResponse httpResponse)
        {
            int productId = 0;
            int.TryParse(httpRequest.QueryString["productId"], out productId);

            if (productId != 0)
            {
                ProductEntity product = logic.product.getById(productId);
                using (JsonTextWriter writer = new JsonTextWriter(httpResponse.Output))
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("productName");
                    writer.WriteValue(product.Name);
                    writer.WritePropertyName("productImage");
                    writer.WriteValue("upload_files/thumbnail1/" + product.ProductImage);
                    writer.WritePropertyName("unit");
                    writer.WriteValue(product.Unit);
                    writer.WritePropertyName("standard");
                    writer.WriteValue(product.Standard);
                    writer.WriteEndObject();
                }
            }
            else
            {
                httpResponse.Output.Write("[]");
            }
        }

        private void listProductList(HttpRequest httpRequest, HttpResponse httpResponse)
        {
            int recipeId = 0;
            int.TryParse(httpRequest.QueryString["recipeId"], out recipeId);
            if (recipeId != 0)
            {
                DataTable dt = logic.recipeItem.listRecipeItemByRecipeId(recipeId);

                StringBuilder jsonBuilder = new StringBuilder("[");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    jsonBuilder.Append("{\"productId\":\"" + dt.Rows[i]["productId"] + "\",\"name\":\"" + dt.Rows[i]["name"] + "\"}");
                    if (i != dt.Rows.Count - 1)
                    {
                        jsonBuilder.Append(",");
                    }
                }
                jsonBuilder.Append("]");
                httpResponse.Write(jsonBuilder.ToString());
            }
        }

        private void listProduct(HttpRequest httpRequest, HttpResponse httpResponse)
        {
            int categoryId = 0;
            int.TryParse(httpRequest.QueryString["category"], out categoryId);

            StringBuilder where = new StringBuilder(" 1=1");
            if (categoryId != 0)
            {
                where.AppendFormat("and categoryId = {0}", categoryId);
                DataSet ds = logic.product.selectmyRecipe(where.ToString(), "productId desc", 10000, 1);
                if (ds.Tables.Count > 1)
                {
                    StringBuilder jsonBuilder = new StringBuilder("[");
                    for (int i = 0; i < ds.Tables[1].Rows.Count; i++)
                    {
                        jsonBuilder.Append("{\"productId\":\"" + ds.Tables[1].Rows[i]["productId"] + "\",\"name\":\"" + ds.Tables[1].Rows[i]["name"] + "\"}");
                        if (i != ds.Tables[1].Rows.Count - 1)
                        {
                            jsonBuilder.Append(",");
                        }
                    }
                    jsonBuilder.Append("]");
                    httpResponse.Write(jsonBuilder.ToString());
                }
                else
                {
                    httpResponse.Write("[]");
                }
            }
            else
            {
                httpResponse.Write("[]");
            }
        }

        private void listSubCateogry(HttpRequest httpRequest, HttpResponse httpResponse)
        {
            int categoryId = 0;
            int.TryParse(httpRequest.QueryString["category"], out categoryId);

            StringBuilder where = new StringBuilder(" 1=1");
            where.Append(" and isShow=1");
            if (categoryId != 0)
            {
                where.AppendFormat(" and parentId={0}", categoryId);
                DataSet ds = logic.category.subList(where.ToString(), "categoryId", 1000, 1);
                if (ds.Tables.Count > 1)
                {
                    httpResponse.Write(DataTableToJson(ds.Tables[1]));
                }
                else
                {
                    httpResponse.Write("[]");
                }
            }
            else
            {
                httpResponse.Write("[]");
            }
        }
        private string DataTableToJson(DataTable dt)
        {
            StringBuilder jsonBuilder = new StringBuilder("[");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                jsonBuilder.Append("{\"categoryId\":\"" + dt.Rows[i]["categoryId"] + "\",\"name\":\"" + dt.Rows[i]["name"] + "\"}");
                if (i != dt.Rows.Count - 1)
                {
                    jsonBuilder.Append(",");
                }
            }
            jsonBuilder.Append("]");

            return jsonBuilder.ToString();
        }

        private void getProductPrice(HttpRequest httpRequest, HttpResponse httpResponse)
        {
            int productId = Convert.ToInt32(httpRequest.QueryString["productId"]);
            string Nature = httpRequest.QueryString["nature"];
            if (logic.customer.userId != 0)
            {
                //查询商品价格图片信息名称
                DataTable dt = logic.product.listWithPriceByCompanyAndProsuctes(logic.customer.getCompanyId(), productId,Nature);
                StringBuilder sb = new StringBuilder("[");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    sb.Append("{");
                    sb.Append("\"productId\":\"" + dt.Rows[i]["productId"] + "\",");
                    sb.Append("\"name\":\"" + dt.Rows[i]["name"] + "\",");
                    sb.Append("\"newprice\":\"" + dt.Rows[i]["newPrice"] + "\",");
                    sb.Append("\"unit\":\"" + dt.Rows[i]["unit"] + "\",");
                    sb.Append("\"systemName\":\"" + dt.Rows[i]["systemName"] + "\",");
                    sb.Append("\"remarks\":\"" + dt.Rows[i]["remarks"] + "\",");
                    sb.Append("\"isCurrentPrice\":\"" + Convert.ToInt32(dt.Rows[i]["isCurrentCost"]) + "\",");
                    sb.Append("\"sellerId\":\"" + dt.Rows[i]["sellerId"] + "\",");
                    sb.Append("\"sellerPrice\":\"" + dt.Rows[i]["sellerPrice"] + "\",");
                    sb.Append("\"bookamount\":\"" + dt.Rows[i]["bookamount"] + "\",");
                    sb.Append("\"businessNature\":\"" + dt.Rows[i]["businessNature"] + "\"");

                    sb.Append("}");
                    if (i != dt.Rows.Count - 1)
                    {
                        sb.Append(",");
                    }
                }
                sb.Append("]");
                httpResponse.Write(sb.ToString());
            }
            else
            {
                httpResponse.Write("[]");
            }
        }


        private void getProductFixedPrice(HttpRequest httpRequest, HttpResponse httpResponse)
        {
            int productId =0;
            int.TryParse(httpRequest.QueryString["productId"].ToString(),out productId);

            string Nature = httpRequest.QueryString["nature"];

            int fpid = 0;
            int.TryParse(httpRequest.QueryString["fpid"].ToString(), out fpid);

            if (logic.customer.userId != 0)
            {
                //查询商品价格图片信息名称
                DataTable dt = logic.product.listWithPriceByCompanyAndProsuctes(logic.customer.getCompanyId(), productId, Nature,fpid);
                StringBuilder sb = new StringBuilder("[");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    sb.Append("{");
                    sb.Append("\"productId\":\"" + dt.Rows[i]["productId"] + "\",");
                    sb.Append("\"name\":\"" + dt.Rows[i]["name"] + "\",");
                    sb.Append("\"newprice\":\"" + dt.Rows[i]["newPrice"] + "\",");
                    sb.Append("\"unit\":\"" + dt.Rows[i]["unit"] + "\",");
                    sb.Append("\"systemName\":\"" + dt.Rows[i]["systemName"] + "\",");
                    sb.Append("\"remarks\":\"" + dt.Rows[i]["remarks"] + "\",");
                    sb.Append("\"isCurrentPrice\":\"" + Convert.ToInt32(dt.Rows[i]["isCurrentCost"]) + "\",");
                    sb.Append("\"sellerId\":\"" + dt.Rows[i]["sellerId"] + "\",");
                    sb.Append("\"sellerPrice\":\"" + dt.Rows[i]["sellerPrice"] + "\",");
                    sb.Append("\"bookamount\":\"" + dt.Rows[i]["bookamount"] + "\",");
                    sb.Append("\"businessNature\":\"" + dt.Rows[i]["businessNature"] + "\"");

                    sb.Append("}");
                    if (i != dt.Rows.Count - 1)
                    {
                        sb.Append(",");
                    }
                }
                sb.Append("]");
                httpResponse.Write(sb.ToString());
            }
            else
            {
                httpResponse.Write("[]");
            }
        }

        private void getProductPriceSpecials(HttpRequest httpRequest, HttpResponse httpResponse)
        {
            int productId = Convert.ToInt32(httpRequest.QueryString["productId"]);
            int bookAmount = 1;
            if (logic.customer.userId != 0)
            {
                //查询商品价格图片信息名称
                DataTable dt = logic.product.listWithPriceByCompanyAndProsuctesSpecials(logic.customer.getCompanyId(), productId);
                StringBuilder sb = new StringBuilder("[");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    sb.Append("{");
                    sb.Append("\"productId\":\"" + dt.Rows[i]["productId"] + "\",");
                    sb.Append("\"name\":\"" + dt.Rows[i]["name"] + "\",");
                    sb.Append("\"newprice\":\"" + dt.Rows[i]["newPrice"] + "\",");
                    sb.Append("\"unit\":\"" + dt.Rows[i]["unit"] + "\",");
                    sb.Append("\"systemName\":\"" + dt.Rows[i]["systemName"] + "\",");
                    sb.Append("\"remarks\":\"" + dt.Rows[i]["remarks"] + "\",");
                    sb.Append("\"isCurrentPrice\":\"" + Convert.ToInt32(dt.Rows[i]["isCurrentCost"]) + "\",");
                    sb.Append("\"sellerId\":\"" + dt.Rows[i]["sellerId"] + "\",");
                    sb.Append("\"sellerPrice\":\"" + dt.Rows[i]["sellerPrice"] + "\",");
                    sb.Append("\"bookamount\":\"" + bookAmount + "\",");
                    sb.Append("\"businessNature\":\"" + dt.Rows[i]["businessNature"] + "\"");
                    sb.Append("}");
                    if (i != dt.Rows.Count - 1)
                    {
                        sb.Append(",");
                    }
                }
                sb.Append("]");
                httpResponse.Write(sb.ToString());
            }
            else
            {
                httpResponse.Write("[]");
            }
        }

        private void getProductPriceByRecepe(HttpRequest httpRequest, HttpResponse httpResponse)
        {
            string strRecepe = httpRequest.QueryString["recepe"].ToString();
            if (logic.customer.userId != 0)
            {
                //查询商品价格图片信息名称
                DataTable dt = logic.product.listWithPriceByCompanyAndRecepe(logic.customer.getCompanyId(), strRecepe);
                StringBuilder sb = new StringBuilder("[");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    sb.Append("{");
                    sb.Append("\"productId\":\"" + dt.Rows[i]["productId"] + "\",");
                    sb.Append("\"name\":\"" + dt.Rows[i]["name"] + "\",");
                    sb.Append("\"newprice\":\"" + dt.Rows[i]["newPrice"] + "\",");
                    sb.Append("\"unit\":\"" + dt.Rows[i]["unit"] + "\",");
                    sb.Append("\"systemName\":\"" + dt.Rows[i]["systemName"] + "\",");
                    sb.Append("\"remarks\":\"" + dt.Rows[i]["remarks"] + "\",");
                    sb.Append("\"isCurrentPrice\":\"" + Convert.ToInt32(dt.Rows[i]["isCurrentCost"]) + "\",");
                    sb.Append("\"sellerId\":\"" + dt.Rows[i]["sellerId"] + "\",");
                    sb.Append("\"sellerPrice\":\"" + dt.Rows[i]["sellerPrice"] + "\",");
                    sb.Append("\"bookamount\":\"" + dt.Rows[i]["bookamount"] + "\",");
                    sb.Append("\"businessNature\":\"" + dt.Rows[i]["businessNature"] + "\"");
                    sb.Append("}");
                    if (i != dt.Rows.Count - 1)
                    {
                        sb.Append(",");
                    }
                }
                sb.Append("]");
                httpResponse.Write(sb.ToString());
            }
            else
            {
                httpResponse.Write("[]");
            }
        }
        private void getByProductNo(HttpRequest httpRequest, HttpResponse httpResponse)
        {
            string productNo = httpRequest.QueryString["ProductNo"].ToString();
            if (productNo!="")
            {
                StringBuilder jsonBuilder = new StringBuilder("[");
                if (logic.product.isExistProductNo(0,productNo))    //商品编号是存在的
                {
                    DataRow dr = logic.product.getByProductNo(productNo);
                    jsonBuilder.Append("{\"productId\":\"" + dr["productId"] + "\",\"productName\":\"" + dr["name"] + "\"}");
                }
                jsonBuilder.Append("]");
                httpResponse.Write(jsonBuilder.ToString());
            }
        }
    }
}
